package org.alino.core.filter.data;

import java.io.Serializable;
import java.util.List;

/**
 * @Desc 数据集合工具类
 * @Author by Brant
 * @Date 2017/1/13
 */
public class Page<T> implements Serializable {

    /**
     * 数据集合
     */
    private List<T> list;
    /**
     * 页码
     */
    private Integer pageNumber;
    /**
     * 页大小
     */
    private Integer pageSize;
    /**
     * 记录总数
     */
    private Integer pageRecord;
    /**
     * 总的页数
     */
    private Integer toltalPage = 0;

    public Page() {
    }

    public Page(List<T> list, Integer pageNumber, Integer pageSize, Integer pageRecord) {
        this.list = list;
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.pageRecord = pageRecord;
        CalculateToltalPage();
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getToltalPage() {
        return toltalPage;
    }

    public void setToltalPage(Integer toltalPage) {
        this.toltalPage = toltalPage;
    }

    public Integer getPageRecord() {
        return pageRecord;
    }

    public void setPageRecord(Integer pageRecord) {
        this.pageRecord = pageRecord;
    }

    private void CalculateToltalPage(){
        if(this.getPageSize()>0 && this.getPageRecord()>0){
            //---------------------------------
            // 总页数=总记录/页大小，不能整除就要进一位
            //---------------------------------
            if(this.getPageRecord() % this.getPageSize() > 0){
                this.setToltalPage(this.getPageRecord()/this.getPageSize() +1);
            }else{
                this.setToltalPage(this.getPageRecord()/this.getPageSize());
            }
        }
    }
}
